package com.chujian.system.auth.controller;

import com.chujian.framework.auth.AccessorHolder;
import com.chujian.framework.core.base.TsDataController;
import com.chujian.framework.core.tsdata.Result;
import com.chujian.sys.vo.menu.Menu;
import com.chujian.system.auth.service.IAuthService;
import com.chujian.system.sys.service.MenuTemplateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("/auth")
@RestController
public class MenuController extends TsDataController {

    @Autowired
    private IAuthService authService;

    @Autowired
    private MenuTemplateService menuTemplateService;

    /**
     * 获取菜单列表
     *
     * @param menuTemplateId 菜单模板ID
     * @return
     */
    @GetMapping("/menu/getMenuList")
    public Result<?> getMenuList(@RequestParam(value = "menuTemplateId", required = false) Long menuTemplateId) {
        if (null == menuTemplateId) {
            menuTemplateId = menuTemplateService.getPcMenuTemplateId();
        }
        List<Menu> menus = authService.getAuthMenuList(AccessorHolder.getUserId(), menuTemplateId);
        return okRs(menus);
    }

    /**
     * 获取小程序菜单列表
     *
     * @return
     */
    @GetMapping("/menu/getMaMenuList")
    public Result<?> getMaMenuList(@RequestParam(value = "menuTemplateId") Long menuTemplateId) {
        Object ops = authService.getAuthMaMenuList(AccessorHolder.getUserId(), menuTemplateId);
        return okRs(ops);
    }

}
